package cn.kpi.service.usualassessment.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import cn.kpi.dao.usualassessment.UserUATZfDao;
import cn.kpi.entity.usualassessment.UserUATMzpdEntity;
import cn.kpi.entity.usualassessment.UserUATZpSummaryEntity;
import cn.kpi.service.usualassessment.IUserUATZfService;

@Service
public class UserUATZfServiceImpl implements IUserUATZfService {
	
	@Autowired
	private UserUATZfDao userUATZfDao;
	
	public List<UserUATMzpdEntity> GetUserZfListProcess(String where,String where2,int year,int quarter,int beginrow,int endrow)throws Exception{
		try{
			
			return userUATZfDao.GetUserZfListProcess(where,where2,year,quarter,beginrow,endrow);
		}
		catch(Exception ex){
			ex.printStackTrace();
			return null;
		}
	}
	public int GetUserZfListProcessCount(String where)throws Exception{
		try{
			return userUATZfDao.GetUserZfListProcessCount(where);
		}
		catch(Exception ex){
			ex.printStackTrace();
			return -1;
		}
	}
	
	@Transactional
	public int UserPjZf(Long userid,int year,int quarter)throws Exception{
		try{
			int result=0;
			result+=userUATZfDao.InsertZpDetail(userid,year,quarter);
			result+=userUATZfDao.DeleteZpDetail(userid,year,quarter);
			result+=userUATZfDao.InsertZpSummary(userid,year,quarter);
			result+=userUATZfDao.DeleteZpSummmary(userid,year,quarter);
			result+=userUATZfDao.InsertZpAtt(userid,year,quarter);
			result+=userUATZfDao.DeleteZpAtt(userid,year,quarter);
			
			result+=userUATZfDao.InsertHpDetail(userid,year,quarter);
			result+=userUATZfDao.DeleteHpDetail(userid,year,quarter);
			result+=userUATZfDao.InsertLdDetail(userid,year,quarter);
			result+=userUATZfDao.DeleteLdDetail(userid,year,quarter);
			result+=userUATZfDao.InsertPjSummary(userid,year,quarter);
			result+=userUATZfDao.DeletePjSummmary(userid,year,quarter);
			
			result+=userUATZfDao.InsertNode(userid,year,quarter);
			result+=userUATZfDao.DeleteNode(userid,year,quarter);
			
			return result;
		}
		catch(Exception ex){
			ex.printStackTrace();
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			return -1;
		}
	}
}
